package top.eleven.sixpence.generaterollbacksql.convertor;

import top.eleven.sixpence.generaterollbacksql.annotation.Convertor;
import top.eleven.sixpence.generaterollbacksql.common.CommonConstant;
import top.eleven.sixpence.generaterollbacksql.common.SQLKey;

import java.util.HashMap;

/**
 *
 *
 * @author Eleven
 */
@Convertor(sqlPrefix = {SQLKey.ALTER_TABLE_C, SQLKey.ALTER_TABLE_L})
public class AlertTableConvertor implements BaseConvertor{
    @Override
    public String convert(String sql) {
        sql = sql.replace(SQLKey.ALTER_TABLE_C, CommonConstant.EMPTY_STRING).replace(SQLKey.ALTER_TABLE_L,CommonConstant.EMPTY_STRING).trim();
        String oldTable = sql.substring(0, sql.indexOf(CommonConstant.ONE_BLANK)).trim();
        sql = sql.substring(sql.indexOf(CommonConstant.ONE_BLANK)).trim();
        String key = sql.substring(0, sql.indexOf(CommonConstant.ONE_BLANK)).trim();
        HashMap<String, Object> convertors = ConvertorManager.build().getConvertors();
        AlertTableConvertor convertor = (AlertTableConvertor) convertors.get(key);
        return convertor.doConvert(oldTable, sql);
    }

    public String doConvert(String table, String sql){
        return "";
    }
}
